package com.yq.homework.day30;


import java.io.FileWriter;
import java.io.IOException;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/06/30 19:54
 */
/*
写1个定时任务,3s的延迟后,每隔5s向文件中写入一行当前时间
 */
public class Demo03 {
    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new MyTest1(),3000,5000);
    }
}

class  MyTest1 extends TimerTask{

    @Override
    public void run() {
        try (FileWriter out = new FileWriter("data.txt", true)){
            out.write(String.valueOf(new Date()));
            out.write("\r\n");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}